package net.chengp.ms.commons.result;

import org.apache.http.HttpStatus;
import org.slf4j.MDC;

import lombok.Data;
import net.chengp.ms.commons.utils.DateUtils;

@Data
public class Result<T> {

	private Integer code = 0;

	private String msg = "调用成功.";

	private T data;

	private String traceId;

	private String timestamp;

	public Result() {
		this.traceId = MDC.get("traceId");
		this.timestamp = DateUtils.now();
	}

	public Result(T data) {
		this();
		this.data = data;
	}

	public Result(ErrorEnum error) {
		this();
		this.code = error.getErrorCode();
		this.msg = error.getErrorMsg();
	}

	public Result(Exception e) {
		this();
		this.code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
		this.msg = e.getMessage();
	}

	public Result(Integer code, String msg) {
		this();
		this.code = code;
		this.msg = msg;
	}

}
